<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Services extends Controller_Common {

	public $template='layout/index';

	public function action_index() {
		$per_page = $this->_config->get('items_per_page');
		$services = ORM::factory('Services')->getAll($this->postfix, $this->getOffset($per_page));

		if (!empty($services)) {
			$this->buildCarcas();
			$this->template->title = 'Zuber - '.$this->sitetext['services']['_value'];
			$this->template->content = View::factory('pages/services', array(
				'services' => $services,
				'items_count' => count($services),
	            'pagination' => Pagination::factory(array(
	            	'view' => 'pagination/basic_'.$this->lang,
	                'total_items' => ORM::factory('Services')->count_all(),
	                'items_per_page' => $this->_config->get('items_per_page'),
	            ))
			));
		} else {
			throw new HTTP_Exception_404(':page does not exist', array(':page' => 'Gaia'));
		}
	}

	public function action_one() {
		$service = ORM::factory('Services')->getOne($this->postfix, $this->request->param('id'));

		if (!empty($service)) {
			$this->buildCarcas();
			$this->template->title = 'Zuber - '.$this->sitetext['services']['_value'].' - '.$service->title.' - '.str_replace(',',' ',number_format($service->price)).' '.$this->sitetext['tenge']['_value'];
			$this->template->description = $service->description;
			$this->template->content = View::factory('pages/oneService', array(
				'service' => $service,
			));
		} else {
			throw new HTTP_Exception_404(':page does not exist', array(':page' => 'Gaia'));
		}
	}
}